﻿
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Jemer.Domain;
using Jemer.Data;
using Jemer.Data.Infrastructure;
using Jemer.Domain.Entities;
using Jemer.Data.Repositories;

namespace Jemer.Service
{
    
    public interface IProductTagService
    {
        IQueryable<ProductTag> GetProductTags();
        ProductTag GetProductTag(int id);
        void CreateProductTag(ProductTag productTag);
        void DeleteProductTag(int id);
        void SaveProductTag();
    }
    
    public class ProductTagService : IProductTagService
    {
        private readonly IProductTagRepository productTagRepository;
        private readonly IUnitOfWork unitOfWork;
        public ProductTagService(IProductTagRepository productTagRepository, IUnitOfWork unitOfWork)
        {
            this.productTagRepository = productTagRepository;
            this.unitOfWork = unitOfWork;
        }  
        #region IProductTagService Members

        public IQueryable<ProductTag> GetProductTags()
        {
            var productTags = productTagRepository.GetAll();
            return productTags;
        }

        public ProductTag GetProductTag(int id)
        {
            var productTag = productTagRepository.GetById(id);
            return productTag;
        }

        public void CreateProductTag(ProductTag productTag)
        {
            productTagRepository.Add(productTag);
            SaveProductTag();
        }

        public void DeleteProductTag(int id)
        {
            var productTag = productTagRepository.GetById(id);
            productTagRepository.Delete(productTag);
            SaveProductTag();
        }

        public void SaveProductTag()
        {
            unitOfWork.Commit();
        }

        #endregion
    }
    
    
}